package facade;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.axis2.AxisFault;
import facade.FacadeInterfaceServiceSkeletonInterface;
import facade.GetEventsByDateFaultException;
import facade.GetEventsByKeywordFaultException;
import facade.GetFacadeGlobalDataFaultException;
import facade.GetMovieInfoByGenreFaultException;
import facade.GetMovieInfoByNameFaultException;
import facade.GetMovieInfoByTheatreFaultException;
import facade.GetMovieInfoByTimeFaultException;
import facade.GetMovieInfoByTypeFaultException;
import facade.GetNewsByCategoryFaultException;
import facade.GetNewsByKeywordFaultException;
import facade.GetRestaurantInfo1ByRatingFaultException;
import facade.GetRestaurantInfoByCusineFaultException;
import facade.GetRestaurantInfoByNameFaultException;
import org.example.www.globalsearch.GetAllData;
import org.example.www.globalsearch.GetAllDataResponse;
import org.example.www.globalsearch.GlobalEvents;
import org.example.www.globalsearch.GlobalMovies;
import org.example.www.globalsearch.GlobalNews;
import org.example.www.globalsearch.GlobalRestaurant;


import org.eventexample.ws.EventsStub;
import org.newsexample.ws.NewsStub;
import org.restaurantexample.ws.RestaurantServiceStub;
import org.sjsufacade.www.facadeinterfaceservice.EventsFacade;
import org.sjsufacade.www.facadeinterfaceservice.EventsFacadeList;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByDate;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByDateFault;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByDateResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByKeyword;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByKeywordFault;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByKeywordResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetFacadeGlobalData;
import org.sjsufacade.www.facadeinterfaceservice.GetFacadeGlobalDataFault;
import org.sjsufacade.www.facadeinterfaceservice.GetFacadeGlobalDataResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByGenre;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByGenreFault;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByGenreResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByName;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByNameFault;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByNameResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTheatre;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTheatreFault;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTheatreResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTime;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTimeFault;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTimeResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByType;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTypeFault;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByTypeResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByCategory;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByCategoryFault;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByCategoryResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByKeyword;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByKeywordFault;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByKeywordResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfo1ByRating;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfo1ByRatingFault;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfo1ByRatingResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByCusine;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByCusineFault;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByCusineResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByName;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByNameFault;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByNameResponse;
import org.sjsufacade.www.facadeinterfaceservice.GlobalFacadeData;
import org.sjsufacade.www.facadeinterfaceservice.MoviesFacade;
import org.sjsufacade.www.facadeinterfaceservice.MoviesFacadeList;
import org.sjsufacade.www.facadeinterfaceservice.NewsFacade;
import org.sjsufacade.www.facadeinterfaceservice.NewsFacadeList;
import org.sjsufacade.www.facadeinterfaceservice.RestaurantFacade;
import org.sjsufacade.www.facadeinterfaceservice.RestaurantFacadeList;
import org.movieexample.www.movie.GetMovieByGenre;
import org.movieexample.www.movie.GetMovieByGenreResponse;
import org.movieexample.www.movie.GetMovieByName;
import org.movieexample.www.movie.GetMovieByNameResponse;
import org.movieexample.www.movie.GetMovieByTheatre;
import org.movieexample.www.movie.GetMovieByTheatreResponse;
import org.movieexample.www.movie.GetMovieByTime;
import org.movieexample.www.movie.GetMovieByTimeResponse;
import org.movieexample.www.movie.GetMovieByType;
import org.movieexample.www.movie.GetMovieByTypeResponse;
import org.movieexample.www.movie.MovieData;

import org.movieexample.ws.MovieServiceStub;

import org.globalSearchexample.ws.GlobalSearchStub;


public class FacadeBusiness implements FacadeInterfaceServiceSkeletonInterface
{

	private static final String RESTAURANT_SERVICE_END_POINT = "http://localhost:8080/axis2/services/RestaurantService";
	private static final String NEWS_SERVICE_END_POINT = "http://localhost:8080/axis2/services/News";
	private static final String EVENTS_SERVICE_END_POINT = "http://localhost:8080/axis2/services/Events";
	private static final String MOVIES_SERVICE_END_POINT = "http://localhost:8080/axis2/services/MovieService";
	private static final String GLOBAL_SERVICE_END_POINT ="http://localhost:8080/axis2/services/GlobalSearch";
	private EventsStub eStub;
	private RestaurantServiceStub rStub;
	private NewsStub nStub;
	private MovieServiceStub mStub;
	private GlobalSearchStub gStub;
	public FacadeBusiness() throws AxisFault
	{
		try
		{
			eStub = new EventsStub(EVENTS_SERVICE_END_POINT);
			rStub = new RestaurantServiceStub(RESTAURANT_SERVICE_END_POINT);
			nStub = new NewsStub(NEWS_SERVICE_END_POINT);
			mStub = new MovieServiceStub(MOVIES_SERVICE_END_POINT);
			gStub = new GlobalSearchStub(GLOBAL_SERVICE_END_POINT);
		}
		catch(AxisFault e)
		{
			System.out.println("Error when creating Individual Services..");
			System.out.println(e.getMessage());
		}
	}
	@Override
	public GetMovieInfoByTimeResponse getMovieInfoByTime(
			GetMovieInfoByTime getMovieInfoByTime)
			throws GetMovieInfoByTimeFaultException {
		try
		{
			GetMovieInfoByTimeResponse response = new GetMovieInfoByTimeResponse();
			
			GetMovieByTime param= new GetMovieByTime();
			param.setIn(getMovieInfoByTime.getIn());
			
			GetMovieByTimeResponse serviceResponse = new GetMovieByTimeResponse();
			serviceResponse = mStub.getMovieByTime(param);
			
			MovieData[] data = serviceResponse.getOut().getMovies();
			MoviesFacadeList movieList = new MoviesFacadeList();
			if(data != null)
			{
				for(int i =0;i<data.length;i++)
				{
					MoviesFacade movie = new MoviesFacade();
					movie.setAddress(data[i].getMovie_location());
					movie.setGenre(data[i].getMovie_type());
					movie.setLatitude(data[i].getMovie_lattitude());
					movie.setLongitude(data[i].getMovie_longitude());
					movie.setMovie_id(data[i].getMovie_Id());
					movie.setMovie_Rating(data[i].getMovie_rating());
					movie.setMovieName(data[i].getMovie_name());
					movie.setShowTime(data[i].getMovie_showTime());
					movie.setTheatreName(data[i].getTheatre_name());
					
					movieList.addMovieList(movie);
				}
			}
			response.setOut(movieList);
			return response;
		}
		catch(Exception e)
		{
			GetMovieInfoByTimeFaultException fault = new GetMovieInfoByTimeFaultException();
			GetMovieInfoByTimeFault msg = new GetMovieInfoByTimeFault();
			msg.setGetMovieInfoByTimeFault(e.getMessage());
			fault.setFaultMessage(msg);
			throw fault;
		}
	}
	@Override
	public GetRestaurantInfoByCusineResponse getRestaurantInfoByCusine(
			GetRestaurantInfoByCusine getRestaurantInfoByCusine)
			throws GetRestaurantInfoByCusineFaultException {
		try
		{
			
			GetRestaurantInfoByCusineResponse response = new GetRestaurantInfoByCusineResponse();
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByCusine parm = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByCusine();
			parm.setIn(getRestaurantInfoByCusine.getIn());
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByCusineResponse res = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByCusineResponse();
			
			res = rStub.getRestaurantInfoByCusine(parm);
			
			
			RestaurantFacadeList result = new RestaurantFacadeList();
			if(res != null){
			result = this.convertRestaurantLists(res.getOut());
			}
			response.setOut(result);
			return response;			
		}
		catch(Exception e)
		{
			GetRestaurantInfoByCusineFault cusineFault = new GetRestaurantInfoByCusineFault();
			cusineFault.setGetRestaurantInfoByCusineFault(e.getMessage());
			GetRestaurantInfoByCusineFaultException error = new GetRestaurantInfoByCusineFaultException();
			error.setFaultMessage(cusineFault);
			throw error;
		}
	}
	@Override
	public GetEventsByDateResponse getEventsByDate(
			GetEventsByDate getEventsByDate)
			throws GetEventsByDateFaultException {
		try
		{
			String start = getEventsByDate.getStart();
			String end = getEventsByDate.getEnd();
			
			//check for required field
			if(start.equalsIgnoreCase("") || end.equalsIgnoreCase("") || start==null || end==null )
			{
				System.err.println("Required fields are not entered!");
				throw new GetEventsByDateFaultException(ErrorMessages.BlankExceptionError);
			}
		
			//check for date validation
			DateFormat formatter ; 
			formatter = new SimpleDateFormat("MM-DD-yyyy");
			Date date1 = null; 
			Date date2 = null;

			try {
				date1 = (Date)formatter.parse(start);
				date2 = (Date)formatter.parse(end);
			} catch (ParseException e) {
				throw new GetEventsByDateFaultException(ErrorMessages.ServiceUnavailableError);
			}
			
			Calendar first = Calendar.getInstance();
			Calendar second = Calendar.getInstance();
			first.setTime(date1);
			second.setTime(date2);
			
			if(second.before(first))
			{
				throw new GetEventsByDateFaultException(ErrorMessages.DateNotValidExceptionError);
			}
			
			org.eventexample.www.events.GetEventsByDate param = new org.eventexample.www.events.GetEventsByDate();
			param.setEnd(getEventsByDate.getEnd());
			param.setStart(getEventsByDate.getStart());
			
			GetEventsByDateResponse object = new GetEventsByDateResponse();
			org.eventexample.www.events.GetEventsByDateResponse serviceResponse = new org.eventexample.www.events.GetEventsByDateResponse();
			
			serviceResponse = eStub.getEventsByDate(param);
			EventsFacadeList array = new EventsFacadeList();
			
			if(serviceResponse != null) {
			EventsFacade[] result = new EventsFacade[serviceResponse.getOut().getEvent().length];
			for(int i=0; i<serviceResponse.getOut().getEvent().length;i++)
			{
				result[i] = this.convertEvents(serviceResponse.getOut().getEvent()[i]);
			}
						
			array.setEventList(result);
			}
			object.setOut(array);
			
			return object;
		}
		catch(Exception e)
		{
			GetEventsByDateFaultException fault = new GetEventsByDateFaultException();
			GetEventsByDateFault msg = new GetEventsByDateFault();
			msg.setGetEventsByDateFault(e.toString());
			fault.setFaultMessage(msg);
			throw fault;
		}
	}
	@Override
	public GetEventsByKeywordResponse getEventsByKeyword(
			GetEventsByKeyword getEventsByKeyword)
			throws GetEventsByKeywordFaultException {
		try
		{
			GetEventsByKeywordResponse object = new GetEventsByKeywordResponse();
			
			if(getEventsByKeyword.getIn().equalsIgnoreCase("") || getEventsByKeyword.getIn() == null)
			{
				System.err.println("Required fields are not entered!");
				throw new GetEventsByKeywordFaultException(ErrorMessages.BlankExceptionError);
			}
			
			org.eventexample.www.events.GetEventsByKeyword param = new org.eventexample.www.events.GetEventsByKeyword();
			param.setKeyword(getEventsByKeyword.getIn());
			
			org.eventexample.www.events.GetEventsByKeywordResponse serviceResponse = new org.eventexample.www.events.GetEventsByKeywordResponse();
			serviceResponse = eStub.getEventsByKeyword(param);
			
			EventsFacadeList array = new EventsFacadeList();
			if(serviceResponse != null)
			{
				org.eventexample.www.events.Event[] eventsResult = serviceResponse.getOut().getEvent();
				
				EventsFacade[] result = new EventsFacade[eventsResult.length];
				for(int i=0; i<eventsResult.length;i++)
				{
					result[i] = this.convertEvents(eventsResult[i]);
				}
				array.setEventList(result);
			}
			object.setOut(array);
			
			return object;
		}
		catch(Exception e)
		{
			GetEventsByKeywordFaultException fault = new GetEventsByKeywordFaultException();
			GetEventsByKeywordFault msg = fault.getFaultMessage();
			System.out.println(e.getMessage());
			System.out.println(e.getLocalizedMessage());
			msg.setGetEventsByKeywordFault(e.getMessage());
			fault.setFaultMessage(msg);
			throw fault;
		}
	}
	@Override
	public GetNewsByCategoryResponse getNewsByCategory(
			GetNewsByCategory getNewsByCategory)
			throws GetNewsByCategoryFaultException {
		GetNewsByCategoryResponse object = new GetNewsByCategoryResponse();
		try
		{
			
			org.newsexample.www.news.GetNewsByCategory param = new org.newsexample.www.news.GetNewsByCategory();
			param.setCategory(getNewsByCategory.getIn());
			
			org.newsexample.www.news.GetNewsByCategoryResponse response = new org.newsexample.www.news.GetNewsByCategoryResponse(); 
			response = nStub.getNewsByCategory(param);
			
			NewsFacadeList array = new NewsFacadeList();
			if(response != null)
			{
				org.newsexample.www.news.News[] newsResult =response.getGetNewsByCategoryResponse().getNews();
				
				NewsFacade[] result = new NewsFacade[newsResult.length];
				for(int i=0; i<newsResult.length;i++)
				{
					result[i] = this.convertNews(newsResult[i]);
				}	
				array.setNews_list(result);
			}
			object.setOut(array);
			
			return object;
		}
		catch(Exception e)
		{
			GetNewsByCategoryFaultException fault = new GetNewsByCategoryFaultException();
			GetNewsByCategoryFault msg  = new GetNewsByCategoryFault();
			msg.setGetNewsByCategoryFault(e.toString());
			fault.setFaultMessage(msg);
			throw fault;
		}
	}
	@Override
	public GetFacadeGlobalDataResponse getFacadeGlobalData(
			GetFacadeGlobalData getFacadeGlobalData)
			throws GetFacadeGlobalDataFaultException {
		GetAllData getAllDataParam = new GetAllData();
		getAllDataParam.setIn("");
		GetAllDataResponse res= new GetAllDataResponse();
		try{
			res = gStub.getAllData(getAllDataParam);
		
			GetFacadeGlobalDataResponse response = new GetFacadeGlobalDataResponse();
			GlobalFacadeData data = new GlobalFacadeData();
			
			//Get Restaurant Data
			if(res != null ){
				if(res.getOut() != null || res.getOut().getRestaurantData() != null)
				{
					RestaurantFacadeList restaurantList = new RestaurantFacadeList();
					GlobalRestaurant[] globalData = res.getOut().getRestaurantData().getRestaurant();
					for(int i =0;i<globalData.length;i++)
					{
						RestaurantFacade restaurant = new RestaurantFacade();
						restaurant.setRestaurant_id(globalData[i].getRestaurant_id());
						restaurant.setRestaurant_latitude(globalData[i].getRestaurant_lattitude());
						restaurant.setRestaurant_location(globalData[i].getRestaurant_location());
						restaurant.setRestaurant_name(globalData[i].getRestaurant_name());
						restaurant.setRestaurant_rating(globalData[i].getRestaurant_rating());
						restaurant.setCuisine(globalData[i].getRestaurant_cusine());
						restaurant.setRestaurant_longitude(globalData[i].getRestaurant_longitude());
						restaurantList.addRestaurantList(restaurant);
					}
					
					data.setRestaurantData(restaurantList);
				}		
			}
			
			//Get Movies Data
			if(res != null )
			{
				if(res.getOut() != null || res.getOut().getMovieData() != null)
				{
					MoviesFacadeList movieList = new MoviesFacadeList();
					GlobalMovies[] globalData = res.getOut().getMovieData().getMovies();
					for(int i =0;i<globalData.length;i++)
					{
						MoviesFacade movie = new MoviesFacade();
						movie.setAddress(globalData[i].getMovie_location());
						movie.setGenre(globalData[i].getMovie_type());
						movie.setLatitude(globalData[i].getMovie_lattitude());
						movie.setLongitude(globalData[i].getMovie_longitude());
						movie.setMovie_id(globalData[i].getMovie_Id());
						movie.setMovie_Rating(globalData[i].getMovie_rating());
						movie.setMovieName(globalData[i].getMovie_name());
						movie.setShowTime(globalData[i].getMovie_showTime());
						movie.setTheatreName(globalData[i].getTheatre_name());
						
						movieList.addMovieList(movie);
					}
					
					data.setMovieData(movieList);
				}
			}
			
			//Get News Data
			if(res != null){
				if(res.getOut() != null || res.getOut().getNewsData() != null)
				{
					NewsFacadeList newsList = new NewsFacadeList();
					GlobalNews[] globalData = res.getOut().getNewsData().getNews();
					for(int i =0;i<globalData.length;i++)
					{
						NewsFacade news = new NewsFacade();
						news.setNews_author(globalData[i].getNews_author());
						news.setNews_category(globalData[i].getNews_category());
						news.setNews_description(globalData[i].getNews_description());
						news.setNews_id(globalData[i].getNews_Id());
						news.setNews_link(globalData[i].getNews_link());
						news.setNews_publication_date(globalData[i].getNews_publicationdate());
						news.setNews_title(globalData[i].getNews_title());
						
						newsList.addNews_list(news);
					}
					
					data.setNewsData(newsList);
				}
			}
			
			//Get Events Data
			if(res != null){
				if(res.getOut() != null || res.getOut().getEventsData() != null)
				{
					EventsFacadeList eventList = new EventsFacadeList();
					GlobalEvents[] globalData = res.getOut().getEventsData().getEvents();
					for(int i =0;i<globalData.length;i++)
					{
						EventsFacade event = new EventsFacade();
						event.setEvent_date_time(globalData[i].getEvent_date_time());
						event.setEvent_description(globalData[i].getEvent_desctiption());
						event.setEvent_id(globalData[i].getEvent_Id());
						event.setEvent_link(globalData[i].getEvent_link());
						event.setEvent_start_date(globalData[i].getEvent_start_date());
						event.setEvent_title(globalData[i].getEvent_title());
						
						eventList.addEventList(event);
					}
					
					data.setEventsData(eventList);
				}
			}
			response.setOut(data);
			return response;
		}
		catch(Exception e)
		{
			GetFacadeGlobalDataFault nameFault = new GetFacadeGlobalDataFault();
			nameFault.setGetFacadeGlobalDataFault(e.toString());
			GetFacadeGlobalDataFaultException error = new GetFacadeGlobalDataFaultException();
			error.setFaultMessage(nameFault);
			throw error;
		}
	}
	@Override
	public GetNewsByKeywordResponse getNewsByKeyword(
			GetNewsByKeyword getNewsByKeyword)
			throws GetNewsByKeywordFaultException {
		try
		{
			if(getNewsByKeyword.getIn().equalsIgnoreCase("") || getNewsByKeyword.getIn() == null)
			{
				System.err.println("Required fields are not entered!");
				throw new GetNewsByKeywordFaultException(ErrorMessages.BlankExceptionError);
			}
			
			GetNewsByKeywordResponse response = new GetNewsByKeywordResponse();
			org.newsexample.www.news.GetNewsByKeyword param = new org.newsexample.www.news.GetNewsByKeyword();
			param.setKeyword(getNewsByKeyword.getIn());
			
			org.newsexample.www.news.GetNewsByKeywordResponse serviceResponse = new org.newsexample.www.news.GetNewsByKeywordResponse();
			serviceResponse = nStub.getNewsByKeyword(param);
			
			org.newsexample.www.news.News[] newsResult = serviceResponse.getGetNewsByKeywordResponse().getNews();
			
			NewsFacade[] result = new NewsFacade[newsResult.length];
			for(int i=0; i<newsResult.length;i++)
			{
				result[i] = this.convertNews(newsResult[i]);
			}
			
			NewsFacadeList array = new NewsFacadeList();
			array.setNews_list(result);
			response.setOut(array);
			
			return response;
		}
		catch(Exception e)
		{
			GetNewsByKeywordFaultException fault = new GetNewsByKeywordFaultException();
			GetNewsByKeywordFault msg = new GetNewsByKeywordFault();
			msg.setGetNewsByKeywordFault(e.toString());
			fault.setFaultMessage(msg);
			throw fault;
		}
	}
	@Override
	public GetRestaurantInfoByNameResponse getRestaurantInfoByName(
			GetRestaurantInfoByName getRestaurantInfoByName)
			throws GetRestaurantInfoByNameFaultException {
		try
		{
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByNameResponse serviceResponse = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByNameResponse();
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByName param = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByName();
			param.setIn(getRestaurantInfoByName.getIn());
			
			GetRestaurantInfoByNameResponse response = new GetRestaurantInfoByNameResponse();
			serviceResponse = rStub.getRestaurantInfoByName(param);
						
			RestaurantFacade result = new RestaurantFacade();
			result = this.convertRestaurant(serviceResponse.getOut());
			
			response.setOut(result);
			return response;
		}
		catch(Exception e)
		{
			GetRestaurantInfoByNameFault nameFault = new GetRestaurantInfoByNameFault();
			nameFault.setGetRestaurantInfoByNameFault(e.getMessage());
			GetRestaurantInfoByNameFaultException error = new GetRestaurantInfoByNameFaultException();
			error.setFaultMessage(nameFault);
			throw error;	
		}
	}
	@Override
	public GetMovieInfoByTheatreResponse getMovieInfoByTheatre(
			GetMovieInfoByTheatre getMovieInfoByTheatre)
			throws GetMovieInfoByTheatreFaultException {
		try
		{
			GetMovieInfoByTheatreResponse response = new GetMovieInfoByTheatreResponse();
			
			GetMovieByTheatre param = new GetMovieByTheatre();
			param.setIn(getMovieInfoByTheatre.getIn());
			
			GetMovieByTheatreResponse serviceResponse = new GetMovieByTheatreResponse();
			serviceResponse = mStub.getMovieByTheatre(param);
			
			MovieData[] data = serviceResponse.getOut().getMovies();
			MoviesFacadeList movieList = new MoviesFacadeList();
			for(int i =0;i<data.length;i++)
			{
				MoviesFacade movie = new MoviesFacade();
				movie.setAddress(data[i].getMovie_location());
				movie.setGenre(data[i].getMovie_type());
				movie.setLatitude(data[i].getMovie_lattitude());
				movie.setLongitude(data[i].getMovie_longitude());
				movie.setMovie_id(data[i].getMovie_Id());
				movie.setMovie_Rating(data[i].getMovie_rating());
				movie.setMovieName(data[i].getMovie_name());
				movie.setShowTime(data[i].getMovie_showTime());
				movie.setTheatreName(data[i].getTheatre_name());
				
				movieList.addMovieList(movie);
			}
			
			response.setOut(movieList);			
			return response;			
		}
		catch(Exception e)
		{
			GetMovieInfoByTheatreFaultException error = new GetMovieInfoByTheatreFaultException();
			GetMovieInfoByTheatreFault fault = new GetMovieInfoByTheatreFault();
			fault.setGetMovieInfoByTheatreFault(e.getMessage());
			error.setFaultMessage(fault);
			throw error;
		}
	}
	@Override
	public GetMovieInfoByTypeResponse getMovieInfoByType(
			GetMovieInfoByType getMovieInfoByType)
			throws GetMovieInfoByTypeFaultException {
		GetMovieInfoByTypeResponse response = new GetMovieInfoByTypeResponse();
		try 
		{
			GetMovieByType param = new GetMovieByType();
			param.setIn(getMovieInfoByType.getIn());
			GetMovieByTypeResponse serviceResponse = new GetMovieByTypeResponse();
			serviceResponse = mStub.getMovieByType(param);
			
			MovieData[] output = serviceResponse.getOut().getMovies();
			MoviesFacadeList data = new MoviesFacadeList();
			if(output != null)
			{
				for(int i =0;i<output.length;i++)
				{
					MoviesFacade movie = new MoviesFacade();
					movie.setAddress(output[i].getMovie_location());
					movie.setGenre(output[i].getMovie_type());
					movie.setLatitude(output[i].getMovie_lattitude());
					movie.setLongitude(output[i].getMovie_longitude());
					movie.setMovie_id(output[i].getMovie_Id());
					movie.setMovie_Rating(output[i].getMovie_rating());
					movie.setMovieName(output[i].getMovie_name());
					movie.setShowTime(output[i].getMovie_showTime());
					movie.setTheatreName(output[i].getTheatre_name());
					data.addMovieList(movie);
				}
			}
			
			response.setOut(data);
		} 
		catch (Exception e) 
		{
			GetMovieInfoByTypeFault fault = new GetMovieInfoByTypeFault();
			GetMovieInfoByTypeFaultException error = new GetMovieInfoByTypeFaultException();
			fault.setGetMovieInfoByTypeFault(e.getMessage());
			error.setFaultMessage(fault);
			throw error;
		}
		
		return response;
	}
	@Override
	public GetMovieInfoByGenreResponse getMovieInfoByGenre(
			GetMovieInfoByGenre getMovieInfoByGenre)
			throws GetMovieInfoByGenreFaultException {
		try
		{
			GetMovieInfoByGenreResponse response = new GetMovieInfoByGenreResponse();
			GetMovieByGenre param = new GetMovieByGenre();
			param.setIn(getMovieInfoByGenre.getIn());
			
			GetMovieByGenreResponse serviceResponse = new GetMovieByGenreResponse();
			serviceResponse = mStub.getMovieByGenre(param);
			
			MovieData[] data = serviceResponse.getOut().getMovies();
			MoviesFacadeList movieList = new MoviesFacadeList();
			for(int i =0;i<data.length;i++)
			{
				MoviesFacade movie = new MoviesFacade();
				movie.setAddress(data[i].getMovie_location());
				movie.setGenre(data[i].getMovie_type());
				movie.setLatitude(data[i].getMovie_lattitude());
				movie.setLongitude(data[i].getMovie_longitude());
				movie.setMovie_id(data[i].getMovie_Id());
				movie.setMovie_Rating(data[i].getMovie_rating());
				movie.setMovieName(data[i].getMovie_name());
				movie.setShowTime(data[i].getMovie_showTime());
				movie.setTheatreName(data[i].getTheatre_name());
				
				movieList.addMovieList(movie);
			}
			
			response.setOut(movieList);
			
			return response;
		}
		catch(Exception e)
		{
			GetMovieInfoByGenreFault fault = new GetMovieInfoByGenreFault();
			fault.setGetMovieInfoByGenreFault(e.getMessage());
			GetMovieInfoByGenreFaultException error = new GetMovieInfoByGenreFaultException();
			error.setFaultMessage(fault);
			throw error;
		}
	}
	
	@Override
	public GetMovieInfoByNameResponse getMovieInfoByName(
			GetMovieInfoByName getMovieInfoByName)
			throws GetMovieInfoByNameFaultException {
		try
		{
			GetMovieInfoByNameResponse response = new GetMovieInfoByNameResponse();
			
			GetMovieByName param = new GetMovieByName();
			param.setIn(getMovieInfoByName.getIn());
			GetMovieByNameResponse serviceResponse = new GetMovieByNameResponse();
			
			serviceResponse = mStub.getMovieByName(param);
			
			MovieData data = serviceResponse.getOut();
			
			MoviesFacade movie = new MoviesFacade();
			if(data != null)
			{	
				movie.setAddress(data.getMovie_location());
				movie.setGenre(data.getMovie_type());
				movie.setLatitude(data.getMovie_lattitude());
				movie.setLongitude(data.getMovie_longitude());
				movie.setMovie_id(data.getMovie_Id());
				movie.setMovie_Rating(data.getMovie_rating());
				movie.setMovieName(data.getMovie_name());
				movie.setShowTime(data.getMovie_showTime());
				movie.setTheatreName(data.getTheatre_name());
			}
			
			response.setOut(movie);
			
			return response;
		}
		catch(Exception e)
		{
			GetMovieInfoByNameFault fault = new GetMovieInfoByNameFault();
			fault.setGetMovieInfoByNameFault(e.getMessage());
			GetMovieInfoByNameFaultException error = new GetMovieInfoByNameFaultException();
			error.setFaultMessage(fault);
			throw error;
		}
	}

//converting functions here...
	
	public EventsFacade convertEvents(org.eventexample.www.events.Event eventArg)
	{
		EventsFacade event = new EventsFacade();
		event.setEvent_date_time(eventArg.getEvent_date_time());
		event.setEvent_description(eventArg.getEvent_description());
		event.setEvent_id(eventArg.getEvent_id());
		event.setEvent_link(eventArg.getEvent_link());
		event.setEvent_start_date(eventArg.getEvent_start_date());
		event.setEvent_title(eventArg.getEvent_title());
		
		return event;
	}
	
	public EventsFacadeList convertGlobalEvents(GlobalEvents[] eventArg)
	{
		EventsFacadeList facadeEventArray = new EventsFacadeList();
		for(int i =0;i<eventArg.length;i++)
		{
			EventsFacade event = new EventsFacade();
			event.setEvent_date_time(eventArg[i].getEvent_date_time());
			event.setEvent_description(eventArg[i].getEvent_desctiption());
			event.setEvent_id(eventArg[i].getEvent_Id());
			event.setEvent_link(eventArg[i].getEvent_link());
			event.setEvent_start_date(eventArg[i].getEvent_start_date());
			event.setEvent_title(eventArg[i].getEvent_title());
			
			facadeEventArray.addEventList(event);
		}
		return facadeEventArray;
	}
	
	public NewsFacade convertNews(org.newsexample.www.news.News newsArg)
	{
		NewsFacade news = new NewsFacade();
		news.setNews_id(newsArg.getNews_id());
		news.setNews_link(newsArg.getNews_link());
		news.setNews_title(newsArg.getNews_title());
		news.setNews_description(newsArg.getNews_description());
		news.setNews_category(newsArg.getNews_category());
		news.setNews_author(newsArg.getNews_author());
		news.setNews_publication_date(newsArg.getNews_publication_date());
		
		return news;
	}

	public RestaurantFacadeList convertRestaurantLists(org.sjsusearch.www.restaurantservice.RestaurantList resArg)
	{
		RestaurantFacadeList result = new RestaurantFacadeList();
		
		org.sjsusearch.www.restaurantservice.Restaurant[] resA = resArg.getRestaurantList();
		RestaurantFacade[] restaurant = new RestaurantFacade[resA.length];
		
		
		for(int i=0;i<resA.length;i++)
		{
			restaurant[i] = new RestaurantFacade();
			restaurant[i].setRestaurant_id(resA[i].getRestaurant_id());
			restaurant[i].setRestaurant_latitude(resA[i].getRestaurant_latitude());
			restaurant[i].setRestaurant_location(resA[i].getRestaurant_location());
			restaurant[i].setRestaurant_longitude(resA[i].getRestaurant_longitude());
			restaurant[i].setRestaurant_name(resA[i].getRestaurant_name());
			restaurant[i].setRestaurant_rating(resA[i].getRestaurant_rating());
			restaurant[i].setCuisine(resA[i].getCuisine());
		}
		
		result.setRestaurantList(restaurant);
		return result;
	}
	public RestaurantFacade convertRestaurant(org.sjsusearch.www.restaurantservice.Restaurant resA)
	{
		RestaurantFacade restaurant = new RestaurantFacade();
		
		restaurant = new RestaurantFacade();
		restaurant.setRestaurant_id(resA.getRestaurant_id());
		restaurant.setRestaurant_latitude(resA.getRestaurant_latitude());
		restaurant.setRestaurant_location(resA.getRestaurant_location());
		restaurant.setRestaurant_longitude(resA.getRestaurant_longitude());
		restaurant.setRestaurant_name(resA.getRestaurant_name());
		restaurant.setRestaurant_rating(resA.getRestaurant_rating());
		restaurant.setCuisine(resA.getCuisine());
		
		return restaurant;
	}
	@Override
	public GetRestaurantInfo1ByRatingResponse getRestaurantInfo1ByRating(
			GetRestaurantInfo1ByRating getRestaurantInfo1ByRating)
			throws GetRestaurantInfo1ByRatingFaultException {
		try
		{
			GetRestaurantInfo1ByRatingResponse response = new GetRestaurantInfo1ByRatingResponse();
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByRatingResponse serviceResponse = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByRatingResponse();
			org.sjsusearch.www.restaurantservice.GetRestaurantInfoByRating param = new org.sjsusearch.www.restaurantservice.GetRestaurantInfoByRating();
			param.setIn(getRestaurantInfo1ByRating.getIn());
			serviceResponse = rStub.getRestaurantInfoByRating(param);
						
			RestaurantFacadeList result = new RestaurantFacadeList();
			result = this.convertRestaurantLists(serviceResponse.getOut());
			
			response.setOut(result);
			return response;
		}
		catch(Exception e)
		{
			GetRestaurantInfo1ByRatingFault ratingFault = new GetRestaurantInfo1ByRatingFault();
			ratingFault.setGetRestaurantInfo1ByRatingFault(e.getMessage());
			GetRestaurantInfo1ByRatingFaultException error = new GetRestaurantInfo1ByRatingFaultException();
			error.setFaultMessage(ratingFault);
			throw error;	
		}
	}
	
}
